package com.city.service.pub.impl;

import com.city.domain.pub.PubHouseinfo;
import com.city.repository.pub.PubHouseinfoRepository;
import com.city.service.pub.PubHouseinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @deprecation:
 * @dmail: 398521613@qq.com
 * @author: L-H
 * @date: 2018-07-25 15:38
 */
@Service
public class PubHouseinfoServiceImpl implements PubHouseinfoService {
    @Autowired
    private PubHouseinfoRepository houseinfoRepository;

    @Override
    public List<PubHouseinfo> getHouseinfoLimit(Integer limitPage, Integer limitNum) {
        return houseinfoRepository.getHouseinfoLimit((limitPage - 1) * limitNum,limitNum);
    }

    @Override
    public PubHouseinfo getHouseinfo(Integer id) {
        return houseinfoRepository.getHouseinfo(id);
    }

    @Override
    public List<PubHouseinfo> getHouseinfoGIS() {
        return houseinfoRepository.getHouseinfoGIS();
    }

    @Override
    public PubHouseinfo getHouseinfoPostion(Integer id) {
        return houseinfoRepository.getHouseinfoPosition(id);
    }

    @Override
    public List<PubHouseinfo> getHouseinfo(PubHouseinfo pubHouseinfo) {
        //创建匹配器，即如何使用查询条件
        ExampleMatcher matcher = ExampleMatcher.matching() //构建对象
                .withMatcher("address", ExampleMatcher.GenericPropertyMatchers.startsWith()); //“开始匹配”的方式查询

        //创建实例
        Example<PubHouseinfo> ex = Example.of(pubHouseinfo, matcher);

        //查询
        return houseinfoRepository.findAll(ex);
    }

    @Override
    public void save(PubHouseinfo pubHouseinfo) {
        houseinfoRepository.save(pubHouseinfo);
    }

    @Override
    public long count(){ return houseinfoRepository.count();}
}
